package com.lc.zpyh.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;

import com.lc.zpyh.R;

import butterknife.ButterKnife;

public class ShopPhomeDialog extends Dialog implements View.OnClickListener {

    private Context context;
    private TextView tv_phone,tv_title;
    private TextView tv_tophone;

    private String sjdh ,title;



    public ShopPhomeDialog(Context context, String title,String sjdh) {
        super(context, R.style.dialog);
        this.context = context;
        this.sjdh=sjdh;
        this.title=title;


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);

        Window window = getWindow();
        window.setGravity(Gravity.CENTER); // 此处可以设置dialog显示的位置为居中
//        window.setWindowAnimations(R.style.bottom_menu_animation); // 添加动画效果
        setContentView(R.layout.dialog_shop_phone);
        WindowManager windowManager = ((Activity) context).getWindowManager();
//        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        DisplayMetrics d = context.getResources().getDisplayMetrics(); // 获取屏幕宽、高
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        lp.width = (int) (d.widthPixels * 0.8);
        getWindow().setAttributes(lp);
        setCanceledOnTouchOutside(true);// 点击Dialog外部消失

        initView();

    }
    private void initView() {

        tv_title = findViewById(R.id.tv_title);
        tv_phone = findViewById(R.id.tv_phone);
        tv_tophone = findViewById(R.id.tv_tophone);
        tv_phone.setText(sjdh);
        tv_tophone.setOnClickListener(this);
        tv_title.setText(title);


    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {

            case R.id.tv_tophone:
                Intent dialIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+sjdh));//跳转到拨号界面，同时传递电话号码
                context.startActivity(dialIntent);
                dismiss();
                break;



            default:
                break;
        }
    }

}
